package com.tsingtree.sys.modular.system.entity;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Objects;

/**
 * <p>
 * 通知表
 * </p>
 *
 * @author  jagger
 * @since 2019-04-01
 */
@TableName("sys_notice")
@Data
@NoArgsConstructor
@Accessors(chain = true)
public class Notice implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 主键
     */
    @TableId(value = "notice_id", type = IdType.ID_WORKER)
    private Long noticeId;

    /**
     * 标题
     */
    @TableField("title")
    private String title;

    /**
     * 内容
     */
    @TableField("content")
    private String content;

    /**
     * 创建时间
     */
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    private LocalDateTime createTime;

    @TableField(exist = false)
    private String createTimeStr;

    public String getCreateTimeStr() {
        if(Objects.isNull(createTime)) return "";
        return createTime.format(DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss"));
    }

    /**
     * 创建人
     */
    @TableField(value = "create_user", fill = FieldFill.INSERT)
    private Long createUser;

    /**
     * 修改时间
     */
    @TableField(value = "update_time", fill = FieldFill.UPDATE)
    private Date updateTime;
    /**
     * 修改人
     */
    @TableField(value = "update_user", fill = FieldFill.UPDATE)
    private Long updateUser;

    @TableField(exist = false)
    private String userName;
    @TableField(exist = false)
    private String roleName;

    public Notice(String title, String content) {
        this.title = title;
        this.content = content;
        this.createTime = LocalDateTime.now();
        this.updateTime = new Date();
    }
}
